package com.adun;

import org.junit.Test;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest {

    @Test
    public void sum() {
        Integer integer = Stream.of(1, 2, 4, 6, 7, 1, 4, 1).distinct().sorted().reduce((r, e) -> r + e).get();
        System.out.printf(integer.toString());
    }

    @Test
    public void sort() {
        Stream.of(1, 2, 4, 6, 7, 1, 4, 1).distinct()
                .sorted()
                .forEach(System.out::println);
    }

    @Test
    public void collect() {
        List<Integer> collect = Stream.of(1, 2, 4, 6, 7, 1, 4, 1)
                .sorted()
                .collect(Collectors.toList());
        collect.forEach(System.out::println);
    }

    @Test
    public void collectSet() {
        Set<Integer> collect = Stream.of(1, 2, 4, 6, 7, 1, 4, 1,9,10,5)
//                .sorted()
                .collect(Collectors.toSet());
        collect.forEach(System.out::println);
    }
}
